package indi.chengx.walty.dirve;

import org.freedesktop.gstreamer.Bus;
import org.freedesktop.gstreamer.Bus.MESSAGE;
import org.freedesktop.gstreamer.BusSyncReply;
import org.freedesktop.gstreamer.Message;
import org.freedesktop.gstreamer.MessageType;
import org.freedesktop.gstreamer.Pipeline;
import org.freedesktop.gstreamer.lowlevel.GstBusAPI.BusCallback;
import org.freedesktop.gstreamer.lowlevel.GstBusAPI.BusSyncHandler;

import com.sun.jna.Pointer;

import indi.chengx.walty.util.Console;

public class CameraCallback implements BusCallback,MESSAGE {
	private Pipeline pipe;
	public CameraCallback(Pipeline pipe) {
		this.pipe = pipe;
		Console.log("CameraCallback", "CameraCallback");
	}
	
	public boolean callback(Bus bus, Message msg, Pointer data) {
		// TODO Auto-generated method stub
		Console.log("CameraCallback", "callback");
		Console.log("CameraCallback","callback =>" + msg.toString());
		if(msg.getType() == MessageType.ELEMENT && msg.getStructure().getName().equals("GstMultiFileSink")) {
			pipe.getElementByName("valve").set("drop", true);
			Console.log("CameraCallback","message GstMultiFileSink");
		}
		return true;
	}

	public void busMessage(Bus bus, Message msg) {
		// TODO Auto-generated method stub
		if(msg.getType() == MessageType.ELEMENT && msg.getStructure().getName().equals("GstMultiFileSink")) {
			pipe.getElementByName("valve").set("drop", true);
			Console.log("CameraCallback","message GstMultiFileSink");
		}
		//Console.log("CameraCallback","callback =>" + message.toString());
	}

}
